<a href="./1.php">日志</a>
<a href="./read_log.php">laravel</a>
<a href="http://81.69.250.186:9003/read_log.php">服务器laravel</a>
<a href="./test.php">php配置信息</a>

<?php
date_default_timezone_set('Asia/Shanghai'); // 设置默认时区为上海

function sendRequest($url, $params = [], $method = 'POST', $options = [])
{
    return "1";
    $method = strtoupper($method);
    $protocol = substr($url, 0, 5);
    $query_string = is_array($params) ? http_build_query($params) : $params;

    $ch = curl_init();
    $defaults = [];

    if ('GET' == $method) {
        $geturl = $query_string ? $url . (stripos($url, "?") !== false ? "&" : "?") . $query_string : $url;
        $defaults[CURLOPT_URL] = $geturl;
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/plain;charset=utf-8"));
    } else {
        $defaults[CURLOPT_URL] = $url;
        if ($method == 'POST') {
            $defaults[CURLOPT_POST] = 1;
        } else {
            $defaults[CURLOPT_CUSTOMREQUEST] = $method;
        }
        if ($params) {
            $defaults[CURLOPT_POSTFIELDS] = $params;
        }
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=utf-8"));
    }
    $defaults[CURLOPT_HEADER] = false;
    $defaults[CURLOPT_USERAGENT] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.98 Safari/537.36";
    if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
        $defaults[CURLOPT_FOLLOWLOCATION] = true;
    }
    $defaults[CURLOPT_RETURNTRANSFER] = true;
    $defaults[CURLOPT_CONNECTTIMEOUT] = 3;
    $defaults[CURLOPT_TIMEOUT] = 3;

    // disable 100-continuea
    //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

    if ('https' == $protocol) {
        $defaults[CURLOPT_SSL_VERIFYPEER] = false;
        $defaults[CURLOPT_SSL_VERIFYHOST] = false;
    }

    curl_setopt_array($ch, (array)$options + $defaults);
    $ret = curl_exec($ch);
    $err = curl_error($ch);
    if (false === $ret || !empty($err)) {
        $errno = curl_errno($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);
        return [
            'ret' => false,
            'errno' => $errno,
            'msg' => $err,
            'info' => $info,
        ];
    }
    curl_close($ch);
    $ret = json_decode($ret, true);

    /*if($ret['c']!==0){
        echo $ret;
    }*/
    return $ret;
}


try {
    $dsn = 'mysql:host=81.69.250.186;dbname=slsclient;charset=utf8';
    $username = 'slsclient';
    $password = 'PL6wsJLkJ5szJnje';
 
    $pdo = new PDO($dsn, $username, $password);
    // 设置错误模式为异常
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    try {
	    // 准备SQL语句
	    $stmt = $pdo->prepare("SELECT * FROM `sls_admin_log` order by id desc");
	    // 执行查询
	    $stmt->execute();
	    // 获取所有结果
	    $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
	    echo "<table border='1'  width='90%' align='center'>";
		echo '<tr bgcolor="#cccccc">';
		echo '<caption>表格</caption>';
		echo  '<th>时间</th><th>ID</th><th>用户id</th><th>手机号</th><th>操作人名字</th><th>type</th><th>user_agent</th><th>REQUEST_URI</th><th>params</th><th>REQUEST_METHOD</th><th>结果</th></tr>';
		
	    // 输出结果
	    foreach ($results as $row) {
	        echo '<tr>';
	        $date = date('Y-m-d H:i:s', $row['create_time']);
	        echo '<td>'.$date.'</td>';
		   	echo '<td>'.$row['id'].'</td>';
		   	echo '<td>'.$row['phone'].'</td>';
		    echo '<td>'.$row['admin_id'].'</td>';
		    echo '<td>'.$row['admin_name'].'</td>';
		    if($row['type']=='2'){
		    	echo '<td>前台</td>';
		    }else{
		    	echo '<td>后台</td>';
		    }
		    
		    echo '<td>'.$row['user_agent'].'</td>';
		    echo '<td>'.$row['REQUEST_URI'].'</td>';
		    echo '<td>'.$row['params'].'</td>';
		    echo '<td>'.$row['REQUEST_METHOD'].'</td>';
		    $url=$row['REQUEST_URI'];
		    if($row['params']){
		    	parse_str($row['params'], $params);
		    	$bb=sendRequest($url, $params);
		    	$bb=json_encode($bb, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
		    }else{
		    	$bb='';
		    }
		   
		    echo '<td>'.$bb.'</td>';
		    echo '</tr>';
	    }
	    echo  '</table>';
	} catch (PDOException $e) {
	    echo "查询失败: " . $e->getMessage();
	}
} catch (PDOException $e) {
    echo "连接失败: " . $e->getMessage();
}